/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ControlLayer;

import ModelLayer.*;
import DBLayer.*;
import java.util.ArrayList;

/**
 *
 * @author Claus
 */
public class CtrSalesOrder
{
	IFDBSalesLineItem dbLineItem;
	IFDBSalesOrder dbSale;
	
	public CtrSalesOrder()
	{
		dbLineItem = new DBSalesLineItem();
		dbSale = new DBSalesOrder();
	}

	public SalesOrder createNewSalesOrder(Customer cus, String date, String deliveryDate, Invoice invoice)
	{
		SalesOrder order = new SalesOrder();

		order.setCustomer(cus);
		order.setDate(date);
		order.setDeliveryDate(deliveryDate);
		order.setDeliveryStatus(SalesOrder.NOTDELIVERED);
		order.setOrderInvoice(invoice);

		return order;
	}

	public SalesLineItem createSalesLineItem(SalesOrder order, Product prod, int quantity)
	{
		SalesLineItem lineItem = new SalesLineItem();
		lineItem.setOrder(order);
		lineItem.setProduct(prod);
		lineItem.setQuantity(quantity);

		return lineItem;
	}

	public void deleteSalesOrder(int id)
	{
		dbSale.deleteSalesOrder(id);
	}

	public int insertSalesOrder(SalesOrder salesObj)
	{
		return dbSale.insertSalesOrder(salesObj);
	}

	public int updateSalesOrder(int salesID, String date, int deliveryStatus, String deliveryDate, Customer cus, Invoice invoice)
	{
		SalesOrder order = new SalesOrder();

		order.setSalesID(salesID);
		order.setCustomer(cus);
		order.setDate(date);
		order.setDeliveryDate(deliveryDate);
		order.setDeliveryStatus(deliveryStatus);
		order.setOrderInvoice(invoice);


		return dbSale.updateSalesOrder(order);
	}

	public SalesOrder findByID(int id)
	{
		
		return dbSale.findSalesOrder(id, true);
	}

	public ArrayList<SalesOrder> findByCustomer(int cusID)
	{
		return dbSale.getCustomerSalesOrders(cusID);
	}

	public ArrayList<SalesOrder> getAllSalesOrders()
	{
		return dbSale.getAllSalesOrders(false);
	}

	public void deleteSalesLineItem(int sliID)
	{
		dbLineItem.deleteSalesLineItem(sliID);
	}

	public void insertSalesLineItem(SalesLineItem item)
	{
		dbLineItem.insertSalesLineItem(item);
	}
}
